<?php


namespace app\root\controller;


use app\model\Circle;
use app\model\Commodity;
use app\model\Discount;
use app\model\Grouppurchase;
use app\model\Shop;
use app\model\Users;

class RootSee {
	function shop(){
		//商家查询总数
		$shops=Shop::Where(['apply_state'=>'true'])->select()->count();
		$shop=Shop::where(['apply_state'=>'false'])->select()->count();
		$users=Users::select()->count();
		return json(['shops'=>$shops,'shop'=>$shop,'users'=>$users]);
	}
	function users(){
		//用户查询
		$users=Users::select();
		return json(['users'=>$users]);
	}
	function commodity(){
		//商家商品表查询
		return Commodity::select();
	}
	function id_shop(){
		//id商家更新状态
		$input  = input('post.');
		Shop::where(['id' => $input['id']])->update(['apply_state'=>'true']);
		return json(['state'=>true]);
	}
	function apply_state(){
		//商家详细状态查询
		$weitong= Shop::where(['apply_state'=>'false'])->select();
		$yitong=Shop::Where(['apply_state'=>'true'])->select();
		return json(['weitong'=>$weitong,'yitong'=>$yitong]);
	}
	function del_shop(){
		//id删除商家
		$input  = input('post.');
		Shop::where(['id' => $input['id']])->delete();
		return json(['state'=>true]);
	}
	function del_users(){
		//id删除用户
		$input  = input('post.');
		Users::where(['id'=>$input['id']])->delete();
		return json(['state'=>true]);
	}
	function fayan() {
		//id查询用户发布的吃货圈
		$input  = input('post.');
		$data = Circle::where(['users_id'=>$input['id']])->select();
		return json(['fayan'=>$data]);
	}
	function shopxq(){
		$input  = input('post.');
		$data1 = Discount::hasWhere('op',['shop_id'=>$input['id']])->with('op')->select();
		$data2 = Grouppurchase::hasWhere('op',['shop_id'=>$input['id']])->with('op')->select();
		$data3 = Commodity::where(['shop_id'=>$input['id']])->select();
		return json(['discount'=>$data1,'grouppurchase'=>$data2,'commodity'=>$data3]);
	}
}